package com.example.lvsuo.controller;


import com.example.lvsuo.entity.CwInvoice;
import com.example.lvsuo.entity.vo.xzhvo.CwInvoiceVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.ICwInvoiceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/cwInvoice")
public class CwInvoiceController {

    @Autowired
    ICwInvoiceService  iCwInvoiceService;

    @PostMapping
    public Result   add(@RequestBody CwInvoice cwInvoice){
        //添加返回值是 long类型 id封装到了实体类 id上
        iCwInvoiceService.add(cwInvoice);
        //取出 添加完成后 返回的主键id
        Long id = cwInvoice.getId();
          return  Result.back(id);
    }

    @GetMapping(value="/{id}")
    public Result   getlistsid(@PathVariable Long id){
       //System.out.println(cwInvoice);
       return  Result.back(iCwInvoiceService.getlist(id));
   }


    @GetMapping()
    public Result   getlists( CwInvoiceVo cwInvoiceVo){
        PageHelper.startPage(cwInvoiceVo.getCurrentPage(),cwInvoiceVo.getPageSize());
        PageInfo pageInfo = new PageInfo(iCwInvoiceService.lists(cwInvoiceVo));
        return    Result.back(pageInfo);

    }

}

